package com.designed.pattern.behavioral.strategy;

import com.designed.pattern.behavioral.strategy.core.CashContext;
import com.designed.pattern.behavioral.strategy.core.CashNormal;
import com.designed.pattern.behavioral.strategy.core.CashRebate;
import com.designed.pattern.behavioral.strategy.core.CashReturn;

import java.util.Random;

/**
 * @author yifei
 * @description
 * @date 2024/1/2
 **/
public class Test {
    static double totalPrices = 0d;
    static double price = 200;
    static int num = 3;

    public static void main(String[] args) {
        // 策略模式
        // strategyM1();
        // 策略 + 工厂
        CashContextEnhance contextEnhance = new CashContextEnhance(new CashReturn(500, 200));
        double result = contextEnhance.getResult(price, num);
        System.out.println(result);
    }

    private static void strategyM1() {
        CashContext cc = null;
        int discount = new Random().nextInt(4);
        switch (discount) {
            case 1:
                cc = new CashContext(new CashNormal());
                break;
            case 2:
                cc = new CashContext(new CashRebate(0.8));
                break;
            case 3:
                cc = new CashContext(new CashRebate(0.6));
                break;
            case 4:
                cc = new CashContext(new CashReturn(300d, 50d));
                break;
        }
        totalPrices = totalPrices + cc.getResult(price, num);
        System.out.println(totalPrices);
    }
}
